﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>877</ArticlesID><Title>Kỹ thuật ph&amp;#226;n trang trong GridView</Title><Body>&amp;lt;p&amp;gt;để Paging trong GridView th&amp;amp;igrave; phải c&amp;amp;oacute; c&amp;amp;aacute;c điều kiện sau: &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
trong  code aspx: &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;amp;lt;asp:GridView ID=&amp;amp;quot;GridView1&amp;amp;quot; &amp;lt;b&amp;gt;AllowPaging=&amp;amp;quot;true&amp;amp;quot;  PageSize=&amp;amp;quot;10&amp;amp;quot;&amp;lt;/b&amp;gt; &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
PageSize l&amp;amp;agrave; số lượng bản ghi tr&amp;amp;ecirc;n 1 trong  của GridView &amp;lt;br /&amp;gt;
AllowPaging l&amp;amp;agrave; cho ph&amp;amp;eacute;p GridView ph&amp;amp;acirc;n trang &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
mở Design click chuột tr&amp;amp;aacute;i v&amp;amp;agrave;o GridView --&amp;amp;gt; chọn Properties &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;img alt=&amp;quot;&amp;quot; src=&amp;quot;../../../../Uploads/admin/2010/4/6/ScreenHunter_001.gif&amp;quot; /&amp;gt;  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;img alt=&amp;quot;&amp;quot; src=&amp;quot;../../../../Uploads/admin/2010/4/6/ScreenHunter_002.gif&amp;quot; /&amp;gt;  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
Click chuột đ&amp;amp;uacute;p sự kiện PageIndexChanging &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
n&amp;amp;oacute; sẽ  Gen ra trong code behind thế n&amp;amp;agrave;y &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;img alt=&amp;quot;&amp;quot; src=&amp;quot;../../../../Uploads/admin/2010/4/6/ScreenHunter_003.gif&amp;quot; /&amp;gt;  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
Viết tiếp 1 h&amp;amp;agrave;m Bind dữ liệu từ Database l&amp;amp;ecirc;n GridView &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;img alt=&amp;quot;&amp;quot; src=&amp;quot;../../../../Uploads/admin/2010/4/6/ScreenHunter_004.gif&amp;quot; /&amp;gt;  &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
trong sự kiện GridView1_PageIndexChanging viết &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
GridView1.PageIndex = e.NewPageIndex; &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
mục đ&amp;amp;iacute;ch l&amp;amp;agrave; set lại  trang hiện tại cho GridView sau đ&amp;amp;oacute; gọi lại ngay h&amp;amp;agrave;m BindGrid() để lấy dữ  liệu mới. &amp;lt;br /&amp;gt;
&amp;lt;br /&amp;gt;
&amp;lt;img alt=&amp;quot;&amp;quot; src=&amp;quot;../../../../Uploads/admin/2010/4/6/ScreenHunter_005.gif&amp;quot; /&amp;gt;              		  &amp;lt;span class=&amp;quot;info&amp;quot;&amp;gt;           &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Để trang web được load nhanh hơn, ch&amp;amp;uacute;ng ta sẽ sử dụng Ajax ở đ&amp;amp;acirc;y:&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Trong code aspx th&amp;amp;ecirc;m dưới thẻ form:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: xhtml;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
        &amp;amp;lt;asp:ScriptManager ID=&amp;amp;quot;ScriptManager1&amp;amp;quot; runat=&amp;amp;quot;server&amp;amp;quot;&amp;amp;gt;
        &amp;amp;lt;/asp:ScriptManager&amp;amp;gt;
        
        &amp;amp;lt;asp:UpdateProgress ID=&amp;amp;quot;UpdateProgress1&amp;amp;quot; runat=&amp;amp;quot;server&amp;amp;quot;&amp;amp;gt;
            &amp;amp;lt;ProgressTemplate&amp;amp;gt;
                &amp;amp;lt;p&amp;amp;gt;Loading&amp;amp;lt;/p&amp;amp;gt;
            &amp;amp;lt;/ProgressTemplate&amp;amp;gt;
        &amp;amp;lt;/asp:UpdateProgress&amp;amp;gt;

        &amp;amp;lt;asp:UpdatePanel ID=&amp;amp;quot;UpdatePanel1&amp;amp;quot; runat=&amp;amp;quot;server&amp;amp;quot;&amp;amp;gt;
            &amp;amp;lt;ContentTemplate&amp;amp;gt;
                &amp;amp;lt;asp:GridView ID=&amp;amp;quot;GridView1&amp;amp;quot; runat=&amp;amp;quot;server&amp;amp;quot; PageSize=&amp;amp;quot;10&amp;amp;quot; AllowPaging=&amp;amp;quot;true&amp;amp;quot; 
                    onpageindexchanging=&amp;amp;quot;GridView1_PageIndexChanging&amp;amp;quot; AutoGenerateColumns=&amp;amp;quot;false&amp;amp;quot;&amp;amp;gt;
                    &amp;amp;lt;Columns&amp;amp;gt;
                    &amp;amp;lt;/Columns&amp;amp;gt;
                &amp;amp;lt;/asp:GridView&amp;amp;gt;                
            &amp;amp;lt;/ContentTemplate&amp;amp;gt;
        &amp;amp;lt;/asp:UpdatePanel&amp;amp;gt;    
&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Như vậy khi &amp;amp;aacute;p dụng Ajax website của ch&amp;amp;uacute;ng ta load nhanh hơn rất nhiều.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;a target=&amp;quot;_blank&amp;quot; href=&amp;quot;http://dev.meotom.net/Uploads/admin/2010/4/7/GridViewPagingDemo.zip&amp;quot;&amp;gt;Download Demo Project&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>4/13/2010 8:24:04 AM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2010/4/7/Ky-thuat-phan-trang-trong-GridView-36D</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>26</CategoryId><ArrayCatID>26|25</ArrayCatID></Article></Articles>